import { MaybePromise } from '@boticord/common'
import { ExecutionContext } from '@nestjs/common'
import { BoticordAbility } from '../casl/ability.type'
import { Token } from '../models/token.model'

export interface IPolicyHandler {
  handle: PolicyHandlerCallback
}

export type PolicyHandlerCallback = 
  (ability: BoticordAbility, context: ExecutionContext, token?: Token) => MaybePromise<boolean>

export type PolicyHandler = (new (...args: any[]) => IPolicyHandler)

export const SimplePolicyHandler = (cb: PolicyHandlerCallback): PolicyHandler => class {
  handle = cb
}